package com.mg.admin.service.admin.impl;

import com.mg.admin.bean.admin.OrganizationVO;
import com.mg.admin.dao.admin.OrganizationMapper;
import com.mg.admin.page.PageBean;
import com.mg.admin.page.PageParam;
import com.mg.admin.service.admin.OrganizationService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("organizationServiceImpl")
public class OrganizationServiceImpl extends BaseService implements OrganizationService {

    @Autowired
    private OrganizationMapper organizationMapper;

	@Override
	public List<OrganizationVO> findChildByParentId(Long orgId) {
		List<OrganizationVO> doList = organizationMapper.findChildByParentId(orgId);
		return doList;
	}


	@Override
	@Transactional
	public void insertOne(OrganizationVO organizationVO) {
		organizationMapper.insertOne(organizationVO);
	}

	@Override
	@Transactional
	public void updateOne(OrganizationVO organizationVO) {
		organizationMapper.updateOne(organizationVO);
	}

	@Override
	@Transactional
	public void delete(Long id) {
		organizationMapper.delete(id);
	}

	@Override
	public OrganizationVO findById(Long id) {
		OrganizationVO organizationVO = organizationMapper.findById(id);
		return organizationVO;
	}

	@Override
	public PageBean findByParentId(Long orgId, PageParam pageParam) {
		RowBounds rb = new RowBounds(pageParam.getStart(),pageParam.getNumPerPage());
		List<OrganizationVO> doList = organizationMapper.findByParentId(orgId,rb);
		Integer totalCount = organizationMapper.getCountByParentId(orgId);
		PageBean pageBean = new PageBean(pageParam.getCurrentPage(),pageParam.getNumPerPage(),totalCount,doList);
		return pageBean;
	}


}